/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLRADIXTREE_H
#define PLRADIXTREE_H

#include <tools/PLRadixTreeVoid.h>
#include <cstddef>
#include <const_operator.h>

namespace PLSDK {

    template<class E>
    class PLRadixTree;

    /**
     * RadixTree template specialisation for pointers. Just forwards to the
     * void* template specialisation of RadixTree.
     *
     * @brief RadixTree template specialisation for pointers.
     */
    template<class T>
    class PLRadixTree<T*> {
    public:
        /**
         * Default constructor, does nothing.
         */
        inline PLRadixTree() : m_VoidRadixTree() {}
        /**
         * Copy-constructor
         *
         * @param x reference object.
         */
        inline PLRadixTree(const PLRadixTree &x) : m_VoidRadixTree(x.m_VoidRadixTree) {}
        /**
         * Destructor, deallocates memory.
         */
        inline ~PLRadixTree() {}
        /**
         * Assignment operator.
         *
         * @param x the object that should be copied.
         */
        inline PLRadixTree &operator = (const PLRadixTree &x) {
            m_VoidRadixTree = x.m_VoidRadixTree;
            return *this;
        }
        /**
         * Get the number of elements in the RadixTree.
         *
         * @return The count.
         */
        inline size_t count() const {
            return m_VoidRadixTree.count();
        }
        /**
         * Add an element to the Tree.
         *
         * @param key the key.
         * @param value the element.
         */
        inline void insert(const char *key, T *value) {
            m_VoidRadixTree.insert(key, reinterpret_cast<void*>(const_cast<typename nonconst_type<T>::type*>(value)));
        }
        /**
         * Attempts to find an element with the given key.
         *
         * @param key the key.
         * @return the element found, or NULL if not found.
         */
        inline T *lookup(const char *key) {
            return reinterpret_cast<T*>(m_VoidRadixTree.lookup(key));
        }
        /**
         * Attempts to remove an element with the given key.
         *
         * @param key the key.
         */
        inline void remove(const char *key) {
            m_VoidRadixTree.remove(key);
        }
        /**
         * Remove all elements from the RadixTree.
         */
        inline void clear() {
            m_VoidRadixTree.clear();
        }
    private:
        // The actual container
        PLRadixTree<void*> m_VoidRadixTree;
    };

}

#endif
